# -*- coding: utf-8 -*-
from model import Collection, db
from time import time


class Good(Collection):
    '''
* `_id` (string)
* `createTime` (long)
* `description` (string)
* `discount` (float)
* `images` (list of string)
* `bigImage` (string)
* `price` (double)
* `sales` (int)
* `title` (string)
* `updateTime` (long)
    '''

    collection = db.good

    class Field(object):
        _id = '_id'
        createTime = 'createTime'
        description = 'description'
        discount = 'discount'
        images = 'images'
        bigImage = 'bigImage'
        price = 'price'
        sales = 'sales'
        title = 'title'
        updateTime = 'updateTime'

    @staticmethod
    def new_good(description, discount, images, big_image, price, title):
        return Good.insert({
            Good.Field.createTime: int(time() * 1000),
            Good.Field.description: description,
            Good.Field.discount: discount,
            Good.Field.images: images,
            Good.Field.bigImage: big_image,
            Good.Field.price: price,
            Good.Field.sales: 0,
            Good.Field.title: title,
            Good.Field.updateTime: int(time() * 1000)
        })
